package com.ruoyi.async;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class FutureThenAcceptTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        futureThenAccept();
        System.out.println("abc");
    }

    public static void futureThenAccept() throws ExecutionException, InterruptedException {
        CompletableFuture<String> orgFuture = CompletableFuture.supplyAsync(
                () -> {
                    try {
                        Thread.sleep(3000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    System.out.println("原始CompletableFuture方法任务");
                    return "捡田螺的小男孩";
                }
        );

        CompletableFuture thenAcceptFuture = orgFuture.thenAccept((a) -> {
            if ("捡田螺的小男孩".equals(a)) {
                System.out.println("关注了");
            }

            System.out.println("先考虑考虑");
        });

//        System.out.println(thenAcceptFuture.get());
    }

}
